﻿#ifndef __SS_THREAD_H__
#define __SS_THREAD_H__

#ifdef SS_USE_BOOST_THREAD
//#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/thread.hpp>
typedef void (*ssThreadFunc_t)();
#elif defined SS_USE_WINDOWS
#include <windows.h>
#include <process.h>
typedef _beginthreadex_proc_type ssThreadFunc_t;
#else
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
typedef void *(*ssThreadFunc_t) (void *);
#endif

namespace StarSeeker
{

class ssThread
{
public:
	ssThread();
	virtual ~ssThread();
	//启动线程
	bool StartThread(ssThreadFunc_t func);
	//等待退出线程
	void WaitForExit();
	//是否运行中
	bool IsRunning() const;
	//线程重新调度，重新调度调用此函数的线程
	static bool Yields();
    //睡眠毫秒，睡眠调用此函数的线程
	static void Sleep(unsigned int ms);
protected:
#ifdef SS_USE_BOOST_THREAD
	boost::thread	*	m_hThread;
#elif defined SS_USE_WINDOWS
	HANDLE				m_hThread;
#else
	pthread_t			m_hThread;
#endif
public:
	unsigned int		m_ThreadId;
};

}
#endif
